package com.xexun.gpstracker.listener;

import android.text.Editable;
import android.text.TextWatcher;

import com.xexun.gpstracker.util.CommUtil;

/**
 * Created by HH
 * Date: 2015/12/1 0001
 * Time: 下午 5:36
 */
public class PrettyTextChangeListener implements TextWatcher {
    private int[] pos;
    private int beforeLen;
    private int afterLen;

    public PrettyTextChangeListener(int... pos) {
        this.pos = pos;
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        beforeLen = s.length();
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        afterLen = s.length();
    }

    @Override
    public void afterTextChanged(Editable s) {
        if (beforeLen != 0 && afterLen != 0 && afterLen != beforeLen) {
            String cont = CommUtil.trimSeprator(s.toString(), null);
            s.clear();
            s.append(CommUtil.prettyString(cont, null, true, pos));
        }
    }
}
